<?php

namespace app\admin\controller;

use app\admin\controller\Utils\JavaCompatible;
use app\app\model\SysDictDataModel;
use app\BaseController;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class sysDictData extends BaseController
{
    /**
     * 查询系统数据
     * @return void
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getDict()
    {
        $type = input('type', '');

        $where = [];
        if ($type) $where[] = ['dict_type', '=', $type];

        $data = SysDictDataModel::where($where)
            ->where('status', 0)
            ->field(['dict_code', 'dict_sort', 'dict_label', 'dict_value', 'is_default'])
            ->select();

        $data = array_map(function ($value) {
            return JavaCompatible::camel($value);
        }, $data->toArray());

        empty($data) && $this->error('查询为空');

        $this->success('success', $data);
    }


}